from pydantic_settings import BaseSettings, SettingsConfigDict
from pathlib import Path
import os

# 获取项目根目录（config.py位于backend/app/config.py）
project_root = Path(__file__).resolve().parent.parent.parent

class Settings(BaseSettings):
    # 环境判断
    ENV: str = "development"
    
    # 数据库配置
    @property
    def DB_PATH(self) -> str:
        if self.ENV == "production":
            return "sqlite:////var/db/production.db"
        return f"sqlite:///{project_root}/app.db"
    
    # JWT配置
    JWT_SECRET: str
    JWT_ALGORITHM: str = "HS256"
    JWT_EXPIRE_MINUTES: int = 30
    
    # 应用配置
    DEBUG: bool = False
    
    @property
    def SQLALCHEMY_DATABASE_URL(self) -> str:
        return self.DB_PATH

    model_config = SettingsConfigDict(
        env_file=".env",
        env_file_encoding="utf-8",
        extra="ignore"
    )

settings = Settings()
